package com.itheima.二维数组;

import java.util.Scanner;

/*
   不死神兔
 */
public class Work11 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int month;
        while (true) {
            System.out.println("请输入月份:");
            month = sc.nextInt();
            if (month < 1) {
                System.out.println("输入有误请重新输入!");
            } else {
                break;
            }
        }
        System.out.println("第" + month + "个月后共有" + num(month) + "对兔子");
    }

    public static int num(int month) {
        int[] arr = new int[month];
        arr[0] = 1;
        if (month == 1) {
            return arr[0];
        } else {
            arr[1] = 1;
            for (int i = 2; i < arr.length; i++) {
                arr[i] = arr[i - 1] + arr[i - 2];
            }
            return arr[month-1];
        }
    }
}
